package com.springboot.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springboot.erp.entity.JshMaterialCurrentStock;
import org.apache.ibatis.annotations.*;

@Mapper
public interface JshMaterialCurrentStockMapper {
    @Select("SELECT * FROM jsh_material_current_stock WHERE id = #{id}")
    JshMaterialCurrentStock findCurrentById(Integer id);

    @Insert("INSERT INTO jsh_material_current_stock" +
            "(material_id,depot_id,current_number,current_unit_price,tenant_id,delete_flag) " +
            "VALUES(#{materialId},#{depotId},#{currentNumber},#{currentUnitPrice},#{tenantId},#{deleteFlag})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void insertCurrent(JshMaterialCurrentStock jshMaterialCurrentStock);

    @Update("update jsh_material_current_stock set material_id=#{materialId},depot_id=#{depotId},current_number=#{currentNumber},current_unit_price=#{currentUnitPrice}," +
            "tenant_id=#{tenantId},delete_flag=#{deleteFlag} where id=#{id}" )
    void updateCurrent(JshMaterialCurrentStock jshMaterialCurrentStock);

    @Delete("DELETE FROM jsh_material_current_stock WHERE id = #{id}")
    void deleteCurrentById(Integer id);

    @Update("update jsh_material_current_stock set current_number=#{currentNumber} where material_id=#{materialId} and depot_id=#{depotId}" )
    void addMaterial(JshMaterialCurrentStock jshMaterialCurrentStock);

    JshMaterialCurrentStock findCurrent(Long materialId, Long depotId);

}
